var scratch_obj={
	scratch_init:function(){
		if(start==true){
			var status='enable';
			var useragent=window.navigator.userAgent.toLowerCase();
			$('#scratchpad').wScratchPad({
				width:120,
				height:36,
				color:'#a9a9a7',
				scratchMove:function(e, percent){
					if (useragent.indexOf("android 4")>0){
						if($("#scratchpad").css("color").indexOf("51")>0){
							$("#scratchpad").css("color", "rgb(50,50,50)");
						}else if($("#scratchpad").css("color").indexOf("50")>0){
							$("#scratchpad").css("color", "rgb(51,51,51)");
						}
					}
					$('#prize').text(prizemsg);
					if(percent>30 && status=='enable'){
						/*this.clear();*/
						status='disable';
						if(data.TId && data.Prize && data.Sn){
							$('#get_prize').show();
							$('#PrizeClass').html(data.Msg);
							$('#SnNumber').html(data.Sn);
							
							//用Ajax生成SESSION
							/*$.post('request/', 'q=1&tid='+data.TId+'&prize='+data.Prize+'&sn='+data.Sn, function(d){
								if(d.status==1){
									//alert('ok');
								}else{
									//alert('error');
								}
							}, 'json');*/
							/*global_obj.win_alert('恭喜您刮中'+data.Msg, function(){
								$('#WinPrize').slideDown(500);
							});*/
						}
					}
				}
			});
		}
		
		$('#get_prize input').click(function(){
			$('#WinPrize').slideDown(500);
			$('#WinPrize input[name=MobilePhone]').focus();
			$('#get_prize').hide();
		});
		
		
		var Phone=$('input[name=MobilePhone]');
		$('#GetPrize').submit(function(){return false;});
		$('#GetPrize input:submit').click(function(){
			if(Phone.val()==''){
				global_obj.win_alert('请填写手机号码！', function(){Phone.focus()});
				return false;
			}
			if(!(/^13\d{9}$/g.test(Phone.val()) || /^14[57]\d{8}$/g.test(Phone.val()) || /^15[0-35-9]\d{8}$/g.test(Phone.val()) || /^18\d{9}$/g.test(Phone.val()))){
				global_obj.win_alert("'"+Phone.val()+"'不是一个有效的手机号码！", function(){Phone.focus()});
				return false;
			}
			
			$(this).attr('disabled', true).val('提交中...');
			var action = $('#GetPrize input[name=action]').attr('value');
			$.post('?'+ action, $('#GetPrize').serialize()+'&q=1', function(data){
				if(data.status==1){
					global_obj.win_alert('提交成功！', function(){
						window.top.location.reload();
					});
					/*$('input, select, textarea').attr('disabled', true);
					$('.submit').val('提交成功');
					$('#scratch_success').show().animate({bottom:150, opacity:'0.7'}, 1500).animate({opacity:0}, 4000);
					$('#WinPrize').hide();
					$('#PrizeTips').show();*/
				}else if(data.status==2 || data.status==3){
					global_obj.win_alert(data.msg, function(){
						$('#GetPrize input:submit').attr('disabled', false).val('提交');
					});
					/*global_obj.win_alert(data.msg, function(){
						$('#WinPrize').slideUp(200);
					});*/
				}else{
					$('#GetPrize input:submit').attr('disabled', false).val('提交');
				};
			}, 'json');
		});
		
		
		$('#PrizeTips .prize_list li span a[href=#usesn]').click(function(){
			var sn=$(this).parent().attr('sn');
			$('#UsedSn').slideDown(200);
			$('#UsedSn #UsedSnNumber').text(sn);
			$('#UsedSn form input[name=sn]').val(sn);
			$('#UsedPrize input[name=bp]').focus();
			return false;
		});
		
		$('#UsedPrize').submit(function(){return false;});
		$('#UsedPrize input:submit').click(function(){
			if($('#UsedPrize input[name=bp]').val()==''){
				global_obj.win_alert('请输入商家密码！', function(){$('#UsedPrize input[name=bp]').focus()});
				return false;
			}
			
			$(this).attr('disabled', true).val('提交中...');
			$.post('?', $('#UsedPrize').serialize()+'&p=1', function(data){
				if(data.status==1){
					global_obj.win_alert('兑奖成功！', function(){window.top.location.reload();});
				}else{
					global_obj.win_alert(data.msg);
				};
				$('#UsedSn').slideUp(200);
				$('#UsedPrize input[name=bp]').val('');
				$('#UsedPrize input:submit').attr('disabled', false).val('提交');
			}, 'json');
		});
		
		$('#UsedPrize .close').click(function(){
			$('#UsedSn').slideUp(200);
		});
	}
}